function [result] = get_cond_mean_prc(dist,gridd,cumsum_dist,cutoff)
    if (isnan(cumsum_dist(end)) || cumsum_dist(end)==0)
        result=nan;
    else
        total=cumsum_dist(end);
        cutoff_grid=find(cumsum_dist>(1-cutoff)*total,1); % it means sum((income_dist(i_t,1:cutoff1))>(1-gridd(i)) but sum((income_dist(i_t,1:cutoff1-1))<(1-gridd(i))
        avg_top=dot(dist(cutoff_grid+1:end),gridd(cutoff_grid+1:end))+...
            (cutoff*total-sum(dist(cutoff_grid+1:end)))*gridd(cutoff_grid);
        avg=dot(dist,gridd);
        result=avg_top/avg;
    end
end